import {
    CHANGE_TOPBANNER,
    CHANGE_HOT_RECOMMEND,
    CHANGE_NEW_ALBUMS,
    CHANGE_UP_RANKING,
    CHANGE_NEW_RANKING,
    CHANGE_ORIGIN_RANKING,
    CHANGE_SETTLE_SONGER,
} from "./constants"
import { getTopBanner, getHotRecommend, getNewAlbums, getTopLists, getArtistList } from "@/services/recommend"

const changeBanners = (res) => ({ type: CHANGE_TOPBANNER, topBanners: res.banners })
export const getTopBannerAction = () => {

    return (dispatch) => {
        getTopBanner().then((res) => {
            dispatch(changeBanners(res))
        })
    }
}



const changeHotRecommendAction = (res) => ({
    type: CHANGE_HOT_RECOMMEND,
    hotRecommends: res.result
})
export const getHotRecommendAction = (limit) => {
    return dispatch => {
        getHotRecommend(limit).then(res => {
            //console.log(res)
            dispatch(changeHotRecommendAction(res));
        })
    }
}
const changeNewAlbumsAction = (res) => ({
    type: CHANGE_NEW_ALBUMS,
    newAlbums: res.albums
})
export const getNewAlbumsActive = (limit) => {

    return (dispatch) => {
        getNewAlbums(limit).then((res) => {
            // console.log(res)
            dispatch(changeNewAlbumsAction(res))
        })
    }
}

const changeUpRankingAction = (res) => ({
    type: CHANGE_UP_RANKING,
    upRanking: res.playlist
})

const changeNewRankingAction = (res) => ({
    type: CHANGE_NEW_RANKING,
    newRanking: res.playlist
})

const changeOriginRankingAction = (res) => ({
    type: CHANGE_ORIGIN_RANKING,
    originRanking: res.playlist
})
export const getTopListAction = (idx) => {
    return dispatch => {
        getTopLists(idx).then(res => {
            switch (idx) {
                case 0:
                    dispatch(changeUpRankingAction(res));
                    break;
                case 2:
                    dispatch(changeNewRankingAction(res));
                    break;
                case 3:
                    dispatch(changeOriginRankingAction(res));
                    break;
                default:
            }
        });
    }
}

const changeSettleSingsAction = (res) => ({
    type: CHANGE_SETTLE_SONGER,
    settleSings: res.artists
})
export const getSettleSingers = () => {
    return dispath => {
        getArtistList(5, 5001).then(res => {
            dispath(changeSettleSingsAction(res))
        })
    }
}